package com.tao.frame;

import com.tao.utils.GenUtils;
import com.tao.utils.MysqlDBUtils;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class ConsoleMain {

    private static  String IP = "";
    private  static String PORT = "";
    private  static String PASS = "";
    private static String USER = "",DATABASE="",PACKAGE,projectPath;





    public static void main(String[] args) throws IOException {

        GenUtils.src = "src/main/java";
        GenUtils.WebRoot = "src/main/resources/templates";
        GenUtils.WebJs = "src/main/resources/static";
        GenUtils.Mapper = "src/main/resources/mapper";

        initData();

        generatorCode(new String []{"ydhl_yizhuinfochangqi","ydhl_zhuyuanbasicinfo"},projectPath);

    }


    private static void initData() throws IOException {
        Properties prop = new Properties();
        prop.load(MainFrame.class.getClassLoader().getResourceAsStream("generator.properties"));

        IP = (prop.getProperty("jdbc.ip", "127.0.0.1"));
        PASS = (prop.getProperty("jdbc.pass", "root"));
        USER = (prop.getProperty("jdbc.user", "root"));
        PORT = (prop.getProperty("jdbc.port", "3306"));
        PACKAGE = (prop.getProperty("package", "com.xm.his"));
        DATABASE = (prop.getProperty("database", "mysql"));
        projectPath = (prop.getProperty("projectPath", ""));


    }


    private static void  generatorCode(String[] tableNames, String projectPath) {
        for (String tableName : tableNames) {
            Map<String, String> table = MysqlDBUtils.getInstanse().queryTable(IP,
                    PORT, PASS, USER, DATABASE,
                    tableName);
            List<Map<String, String>> columns = MysqlDBUtils.getInstanse().queryColumns(IP,
                    PORT, PASS, USER, DATABASE,
                    tableName);
            GenUtils.generatorCode(table, columns, null, false, projectPath, PACKAGE);
        }

    }
}
